<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>分店销售页面</title>
	<link rel="stylesheet" href="../../res/mln/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
    .demoTable{
    	z-index: 10px;
    }
    #addReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #addOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
     #updateReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #updateOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
  </style>
</head>
<body>
	<div class="demoTable">
	  搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="dateOne" id="dateOne" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="dateTwo" id="dateTwo" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
	  <table class="layui-hide" id="fdSell" lay-filter="demo"></table>
	</div>
	
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="detail" id="cxxq">查看销售详情</a>
 
{{# if(d.tuihuo=="0"){ }}
   <a class="layui-btn layui-btn-disabled  layui-btn-xs" lay-event="salesReturn">退货</a>
{{# } else if(d.tuihuo==1){}}
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="salesReturn">退货</a>

{{# } }}
</script>

<script src="../../res/mln/jquery-1.10.2.js"></script>
<script src="../../res/mln/layui-xtree.js"></script>
<script src="../../res/mln/layui.js"></script>
<script src="../../res/js/base.js"></script>
<script src="../../layui/layui.js"></script>
<script>

layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
  
  
  var endDate= laydate.render({
      elem: '#dateTwo',//选择器结束时间
      //type: 'datetime',
      min:"2001-12-31",//设置min默认最小值  0表示今天 -1表示昨天  1表示明天
      max:"2099-12-31",
      done: function(value,date){
          startDate.config.max={
              year:date.year,
              month:date.month-1,//关键
              date: date.date
             
          }
      }
  });
  //日期范围
  var startDate=laydate.render({
      elem: '#dateOne',
    //  type: 'datetime',
      min:"2001-12-31",
      max:"2099-12-31",//设置一个默认最大值
      done: function(value, date){
          endDate.config.min ={
              year:date.year,
              month:date.month-1, //关键
              date: date.date
             
          };
      }
  });
  
  //日期
  laydate.render({
	    elem: '#dateOne'
  });
  laydate.render({
	    elem: '#dateTwo'
  });

  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#fdSell'
    ,async: false
    ,height: 374
    ,url: path+'fdSell/findAllFdSell.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'memberId', title: '会员ID', width:80}
      ,{field: 'sellName', title: '销售人', width:80}
      ,{field: 'sellDates', title: '销售时间', width:180}
      ,{field: 'sellTotalMoney', title: '销售金额', width:120 ,sort: true}
      ,{field: 'sellTotalNumber', title: '销售总数量', width:120,sort: true}
      ,{field: 'serNumber', title: '流水号', width:120}
      ,{field: 'sellMoney', title: '实收款', width:120,sort: true}
      ,{field: 'sellChange', title: '找零', width:120,sort: true}
      ,{fixed: 'right',title: '操作', width: 240, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    if(layEvent === 'detail'){
    	var sellId=data.sellId;
    	sessionStorage["sellId"]=sellId;
    	var url="../mln/fdSellList.html?sellId="+sellId;
    	layer.open({
			  type: 2,
			  area : ['75%' , '70%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: [url,'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			});
    } else if(layEvent === 'salesReturn'){
    	var tuihuo = data.tuihuo;
    	//判断退货与 已退货状态
    	if(tuihuo==0){
    		 layer.msg('订单已退货，无法操作', {
				  icon: 1,
				  time: 3000 //1秒关闭（如果不配置，默认是3秒）
				}, function(){
					// location.reload(); // 页面刷新
			});
    	}
    	
    	if(tuihuo==1){
    		var sellId = data.sellId;  		
    	
    		layer.open({
    			title:'分店销售详情'
    			,type:2
    			,area:['85%','80%']
    			//设置滚蛋条 yes为开启  no为关闭
    			,content:[path+'pages/mln/fdSellDetail.html?sellId='+sellId,'yes']
    		});
   		}
    	
    	
 
    }
    
    });

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					sellName : demoReload.val(),
					dateOne: $("#dateOne").val(),
					dateTwo: $("#dateTwo").val()
				}
				
			});
		});
		$('#closeAdd').on('click', function() {
			$('#addReload').css('display', 'none');
		});
		$('#closeUpdate').on('click', function() {
			
			$('#updateReload').css('display', 'none');
		});
		
		$('#memberAdd').on('click', function() {
			layer.open({
				  type: 2,
				  area : ['85%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: ['../yuanwei/FdSellDetailadd.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				});
		});
		
		
		
		
	});
</script>
</body>
</html>